<?php

/**
* CodeListTest.php
*
* Guid add test
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once '../framework/config.php';

require_once 'simpletest/autorun.php';
require_once 'simpletest/web_tester.php';

require_once '../framework/AuthSingleton.php';

class  CodeListTest extends WebTestCase
{

    private $dbh = '';
    private $username = '';
    private $password = '';


    public function setUp() 
    {
        $this->username = md5( uniqid( rand(), true ) )."@pl.pl";
        $this->password = "zuza";

        $this->adminUsername = md5( uniqid( rand(), true ) )."@pl.pl";
        $this->adminPassword = "zuza";

        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $this->url = rtrim($global['service_url'],'/');

        $locale =  &PEAR::getStaticProperty('CONFIG_INI','LOCALE');
        $this->locale = $locale['default_locale']; 
        
        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');  
        $this->dbh = new PDO($options['dsn_string']); 
        $this->dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );


        $this->addHeader("User-Agent: Mozilla/5.0(SymbianOS/9.2; U; Series60/3.1 NokiaE51/1.00.000; Profile/MIDP-2.0 Configuration/CLDC-1.1;)AppleWebKit/413(KHTML,like Gecko)Safari/413");


        $this->get($this->url.'?');
        AuthSingleton::instance('AUTH_USER')->addUser($this->username,$this->password);
        $this->setFieldByName('username', $this->username);
        $this->setFieldByName('password', $this->password);
        $this->click("Login");
        $this->assertTitle('Polowanie na kody');
        $this->assertText('Mapa poglądowa oraz lista trofeów');


    }

    public function testEmptyCodeList()
    {
        $this->get($this->url.'?cmd=CodeList');
        $this->assertText('Brak kodów','This will pass only if DB is empty ');  
 
    }

    public function testCodeListNoHuntedCode()
    {

        $sth = $this->dbh->prepare('INSERT INTO guide (code, owner, publish) VALUES (:code_id,:owner,:publish) ');
        $sth -> bindValue(':code_id','000001',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000002',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000003',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[1] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test2' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[2] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test3' ,PDO::PARAM_STR);
        $sth->execute();        

        $this->get($this->url.'?cmd=CodeList');

        $this->assertLink('test1-',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/1.*notHuntedCodeList.*2/');
        $this->assertLink('test2-',$this->url.'/?cmd=ShowCode&id='.$idArray[1]);
        $this->assertPattern('/2.*notHuntedCodeList.*3/');
        $this->assertLink('test3-',$this->url.'/?cmd=ShowCode&id='.$idArray[2]);
        $this->assertPattern('/2.*3.*notHuntedCodeList/');

        
    }

  

    public function testCodeListTranslation()
    {

        $sth = $this->dbh->prepare('INSERT INTO guide (code, owner, publish) VALUES (:code_id,:owner,:publish) ');
        $sth -> bindValue(':code_id','000001',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000002',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000003',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[1] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test2' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[2] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test3' ,PDO::PARAM_STR);
        $sth->execute();        
        

        $this->get($this->url.'?cmd=CodeList');


        $this->assertLink('test1-',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/1.*notHuntedCodeList.*2/');
        $this->assertLink('test2-',$this->url.'/?cmd=ShowCode&id='.$idArray[1]);
        $this->assertPattern('/2.*notHuntedCodeList.*/');
        $this->assertNoLink('test3-',$this->url.'/?cmd=ShowCode&id='.$idArray[2]);

        $this->get($this->url.'?cmd=CodeList&locale=en_GB');

        $this->assertLink('No translation for en_GB-',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/1.*notHuntedCodeList.*2/');

        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  'en_GB' ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $this->get($this->url.'?cmd=CodeList&locale=en_GB');

        $this->assertLink('test1-',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/1.*notHuntedCodeList.*2/');


    }

    public function testCodeListHuntedCodeAndNotHuntedCode()
    {

        $sth = $this->dbh->prepare('INSERT INTO guide (code, owner, publish) VALUES (:code_id,:owner,:publish) ');
        $sth -> bindValue(':code_id','000001',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId();

        $sth -> bindValue(':code_id','000002',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000003',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[1] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test2' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[2] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test3' ,PDO::PARAM_STR);
        $sth->execute();        

        $upload = &PEAR::getStaticProperty('CONFIG_INI','UPLOAD');
        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[0]."image.jpg' WHERE rowid=".$idArray[0]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[0].'image.jpg');     

        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[1]."image.jpg' WHERE rowid=".$idArray[1]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[1].'image.jpg');     

        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[2]."image.jpg' WHERE rowid=".$idArray[2]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[2].'image.jpg');     



        $sth = $this->dbh->prepare('INSERT INTO hunted_code (code_id, owner, time) VALUES (:code_id,:owner,:time) ');
        $sth -> bindValue(':code_id',$idArray[0],PDO::PARAM_INT);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[1],PDO::PARAM_INT);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();


        $this->get($this->url.'?cmd=CodeList');


        $this->assertLink('test1+',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/\d+.*huntedCodeList.*\d+/');
        $this->assertLink('test2+',$this->url.'/?cmd=ShowCode&id='.$idArray[1]);
        $this->assertPattern('/\d+.*huntedCodeList.*\d+/');
        $this->assertLink('test3-',$this->url.'/?cmd=ShowCode&id='.$idArray[2]);
        $this->assertPattern('/\d+.*\d+.*notHuntedCodeList/');




    }

    public function testCodeListAllHunted()
    {


        $sth = $this->dbh->prepare('INSERT INTO guide (code, owner, publish) VALUES (:code_id,:owner,:publish) ');
        $sth -> bindValue(':code_id','000001',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000002',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000003',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 


        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[1] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test2' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[2] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test3' ,PDO::PARAM_STR);
        $sth->execute();        

        $upload = &PEAR::getStaticProperty('CONFIG_INI','UPLOAD');
        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[0]."image.jpg' WHERE rowid=".$idArray[0]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[0].'image.jpg');     

        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[1]."image.jpg' WHERE rowid=".$idArray[1]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[1].'image.jpg');     

        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[2]."image.jpg' WHERE rowid=".$idArray[2]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[2].'image.jpg');     

        $sth = $this->dbh->prepare('INSERT INTO hunted_code (code_id, owner, time) VALUES (:code_id,:owner,:time) ');
        $sth -> bindValue(':code_id',$idArray[0],PDO::PARAM_INT);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[1],PDO::PARAM_INT);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[2],PDO::PARAM_INT);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $this->get($this->url.'?cmd=CodeList');

        $this->assertLink('test1+',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/\d+.*huntedCodeList.*\d+/');
        $this->assertLink('test2+',$this->url.'/?cmd=ShowCode&id='.$idArray[1]);
        $this->assertPattern('/\d+.*huntedCodeList.*\d+/');
        $this->assertLink('test3+',$this->url.'/?cmd=ShowCode&id='.$idArray[2]);
        $this->assertPattern('/\d+.*\d+.*huntedCodeList/');

    }

    public function testCodeListOfTwoUsers()
    {

        $sth = $this->dbh->prepare('INSERT INTO guide (code, owner) VALUES (:code_id,:owner) ');
        $sth -> bindValue(':code_id','000001',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000002',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000003',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000004',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId();

        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[1] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test2' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[2] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test3' ,PDO::PARAM_STR);
        $sth->execute();        

        $sth -> bindValue(':guide_id', $idArray[3] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test4' ,PDO::PARAM_STR);
        $sth->execute();        
        

        $upload = &PEAR::getStaticProperty('CONFIG_INI','UPLOAD');
        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[0]."image.jpg' WHERE rowid=".$idArray[0]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[0].'image.jpg');     

        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[1]."image.jpg' WHERE rowid=".$idArray[1]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[1].'image.jpg');     

        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[2]."image.jpg' WHERE rowid=".$idArray[2]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[2].'image.jpg');     
 
        $this->dbh->exec("UPDATE guide SET  pic_file = '".$idArray[3]."image.jpg' WHERE rowid=".$idArray[3]);
        copy( dirname(__FILE__).'/image.jpg', $upload['upload_dir'].$idArray[3].'image.jpg');     



        $sth = $this->dbh->prepare('INSERT INTO hunted_code (code_id, owner, time) VALUES (:code_id,:owner,:time) ');
        $sth -> bindValue(':code_id',$idArray[0],PDO::PARAM_INT);
        $sth -> bindValue(':owner', 'second'.$this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[1],PDO::PARAM_INT);
        $sth -> bindValue(':owner', 'second'.$this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[2],PDO::PARAM_INT);
        $sth -> bindValue(':owner', 'second'.$this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[2],PDO::PARAM_INT);
        $sth -> bindValue(':owner', 'second'.$this->username ,PDO::PARAM_STR);
        $sth -> bindParam(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();

        $sth -> bindValue(':code_id',$idArray[3],PDO::PARAM_INT);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindValue(':time',  time() ,PDO::PARAM_INT);
        $sth->execute();


        $this->get($this->url.'?cmd=CodeList');

        $this->assertLink('test1-',$this->url.'/?cmd=ShowCode&id='.$idArray[0]);
        $this->assertPattern('/\d+.*notHuntedCodeList.*\d+/');
        $this->assertLink('test2-',$this->url.'/?cmd=ShowCode&id='.$idArray[1]);
        $this->assertPattern('/\d+.*notHuntedCodeList.*\d+/');
        $this->assertLink('test3-',$this->url.'/?cmd=ShowCode&id='.$idArray[2]);
        $this->assertPattern('/\d+.*\d+.*notHuntedCodeList/');
        $this->assertLink('test4+',$this->url.'/?cmd=ShowCode&id='.$idArray[3]);
        $this->assertPattern('/\d+.*\d+.*huntedCodeList/');


        
    }


    public function testMapeSize()
    {

        $testName = md5(uniqid(rand(), true));
        $testDesc = md5(uniqid(rand(), true));
        $testGeoCode = "Mirsk,PL";        

        $sth = $this->dbh->prepare('INSERT INTO guide (code, owner, publish,geocode) VALUES (:code_id,:owner,:publish,:geocode)');
        $sth -> bindValue(':code_id','000001',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->adminUsername ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '1' ,PDO::PARAM_INT);
        $sth -> bindValue(':geocode', $testGeoCode,PDO::PARAM_STR);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 

        $sth -> bindValue(':code_id','000002',PDO::PARAM_STR);
        $sth -> bindParam(':owner', $this->username ,PDO::PARAM_STR);
        $sth -> bindValue(':publish',  '' ,PDO::PARAM_INT);
        $sth->execute();
        $idArray[] = $this->dbh->lastInsertId(); 


        $sth = $this->dbh->prepare('INSERT INTO guide_name (guide_id,name,locale) VALUES (:guide_id,:name,:locale) ');

        $sth -> bindValue(':guide_id', $idArray[0] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test1' ,PDO::PARAM_STR);
        $sth->execute();

        $sth -> bindValue(':guide_id', $idArray[1] ,PDO::PARAM_INT);
        $sth -> bindValue(':locale',  $this->locale ,PDO::PARAM_STR);
        $sth -> bindValue(':name',  'test2' ,PDO::PARAM_STR);
        $sth->execute();

        $this->get($this->url.'/?cmd=CodeList');
        $this->assertTitle('Polowanie na kody');
        $this->assertPattern('/.*&size=229x320.*/');
        $this->assertText("Mapa poglądowa (1)");



        
    }    

    public function tearDown() 
    {

        AuthSingleton::instance('AUTH_USER')->removeUser($this->username);

        $upload = &PEAR::getStaticProperty('CONFIG_INI','UPLOAD'); 
        $sth = $this->dbh->query("SELECT pic_file,rowid FROM guide WHERE  owner='".$this->username."'");
        
        for($i=0; $result = $sth->fetch(); $i++){
            
            $this->dbh->exec("DELETE FROM guide_name WHERE guide_id='".$result['rowid']."'");

            if ( is_file($upload['upload_dir'].$result['pic_file']) )
            {
                unlink($upload['upload_dir'].$result['pic_file']);
            }
        }

        $sth = $this->dbh->query("SELECT pic_file,rowid FROM guide WHERE  owner='".$this->adminUsername."'");
        
        for($i=0; $result = $sth->fetch(); $i++){

            $this->dbh->exec("DELETE FROM guide_name WHERE guide_id='".$result['rowid']."'");

            if ( is_file($upload['upload_dir'].$result['pic_file']) )
            {
                unlink($upload['upload_dir'].$result['pic_file']);
            }
        }

        $this->dbh->exec("DELETE FROM guide WHERE owner='".$this->username."'");
        $this->dbh->exec("DELETE FROM guide WHERE owner='".$this->adminUsername."'");

        $this->dbh->exec("DELETE FROM hunted_code WHERE owner='".$this->username."'");
        $this->dbh->exec("DELETE FROM hunted_code WHERE owner='first".$this->username."'");
        $this->dbh->exec("DELETE FROM hunted_code WHERE owner='second".$this->username."'");
        $dbh = null;
        
    }
 

}
?>
